#include "WinsockEveInit.h"
#ifdef WIN32
#include <winsock2.h>
#include <windows.h>
#else
#endif
CWinsockEveInit::CWinsockEveInit()
	:bInit(false)
{
}


CWinsockEveInit::~CWinsockEveInit()
{
	if (bInit)
	{
		WSACleanup();
	}
}

int CWinsockEveInit::Initialize()
{
	WSADATA wsaData;
	int err = WSAStartup(MAKEWORD(2, 2), &wsaData);
	if (err != 0) {
		return 1;
	}
	if (LOBYTE(wsaData.wVersion) != 2 || HIBYTE(wsaData.wVersion) != 2)
	{
		WSACleanup();
		return 2;
	}

	bInit = true;

	return 0;
}
